<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld"  prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld"  prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tlds/custom-html.tld" prefix="chtml" %>

<%@ page  import="java.util.*" %>
<%@ page  import="com.erp.framework.util.CommonUtil" %>
<%@ page  import="com.erp.app.common.ProjectConstants" %>
<%@ page  import="com.erp.app.util.web.WebUtil" %>

<jsp:useBean id="selectRemarkTextForm" scope="session" type="com.erp.common.web.SelectRemarkTextForm" />

<%

HashMap params = selectRemarkTextForm.getParams();
boolean readonly = !CommonUtil.isEmpty(params.get(ProjectConstants.SESSION_SIMPLE_READ_ONLY));
boolean hideRemarkMaster = !CommonUtil.isEmpty(params.get(ProjectConstants.SESSION_SIMPLE_HIDE_REMARK_MASTER));
boolean hideRemarkDetail = !CommonUtil.isEmpty(params.get(ProjectConstants.SESSION_SIMPLE_HIDE_REMARK_DETAIL));
boolean hideRemarkAppend = !CommonUtil.isEmpty(params.get(ProjectConstants.SESSION_SIMPLE_HIDE_REMARK_APPEND));
boolean useHtmlCode = !CommonUtil.isEmpty(params.get(ProjectConstants.SESSION_USE_HTML_CODE));

%>

<head>
<title>Remark Input</title>
<link rel="stylesheet" href="<%=request.getContextPath()+ "/css/style.css" %>" type="text/css">

<script language="javascript">
<!--
var isSubmitted = 0;
 
function doSubmit(event) {
    document.forms[0].pageEvent.value = event;
    isSubmitted = 1;
    document.forms[0].submit();
}

function doLoad() {
	<% 
	if (!CommonUtil.isEmpty(selectRemarkTextForm.getPageEvent())) {
		if (!(selectRemarkTextForm.getPageEvent().equals("changeMaster") || (selectRemarkTextForm.getPageEvent().equals("changeDtl")) || (selectRemarkTextForm.getPageEvent().equals("erase")) )) {
			if (selectRemarkTextForm.getPageEvent().equals("ok")) {
				out.println("window.opener.doSubmit('doNothing');");
			}

			selectRemarkTextForm.setSelectedRemarkMaster("");
			selectRemarkTextForm.setSelectedRemarkDtl(""); 
			out.println("self.close();");
		}
	}

	%>
	window.resizeTo(750, 550);
	window.moveTo(0, 0);
}
function doAppend() {
    var val = document.forms[0].append.value;
    if (val == '<%=ProjectConstants.GENERIC_YES%>')
        document.forms[0].append.value = '<%=ProjectConstants.GENERIC_NO%>';
    else 
        document.forms[0].append.value = '<%=ProjectConstants.GENERIC_YES%>';
}
-->
</script>

<script language="Javascript1.2"><!-- // load htmlarea
_editor_url = "js/htmlarea/";                     // URL to htmlarea files
var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);
if (navigator.userAgent.indexOf('Mac')        >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Windows CE') >= 0) { win_ie_ver = 0; }
if (navigator.userAgent.indexOf('Opera')      >= 0) { win_ie_ver = 0; }
if (win_ie_ver >= 5.5) {
  document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js"');
  document.write(' language="Javascript1.2"></scr' + 'ipt>');
} else { document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); }
// --></script>

</head>
<body onLoad="javascript:doLoad();" bgcolor="#ffffff">

<html:form action="/selectRemarkText">
<html:hidden property="pageEvent" />
<html:hidden property="pageMode" />

<table bgcolor="#E0E6E7" border=1 bordercolor="#C1C1C1" cellpadding=0 cellspacing=0 width=100%>
<%
    LinkedList keyList = (LinkedList) params.get(ProjectConstants.SESSION_KEY_LIST);
	if(keyList != null){
		Iterator iterator = keyList.iterator();
		while (iterator.hasNext()) {
			String key = (String) iterator.next();
			String value = (String) iterator.next();
	%>
	<tr valign="top">
		<td class="col_label"><%= key %>:</td>
		<td class="col_value"><%= value %></td>
	</tr>
<% 
	}
}
%>

<%
	String where = "";
	String disabledHtml = (readonly) ? " disabled " : "";
%>
<%
if (!hideRemarkMaster) {
%>
<tr valign="top">
	 <td class="col_label">
		Remark Master Code:
	 <td class="col_value">
		<%
			where = "company_code = '" + WebUtil.getAppropriateCompanyCode(session, ProjectConstants.SP_SHARE_REMARK) + "' and status = '"+ProjectConstants.GENERIC_ACTIVE+"'";
		%>
		<select name="selectedRemarkMaster" class="selectBox1" onchange="doSubmit('changeMaster');" <%=disabledHtml%> >
		<option value=""></option>
			<chtml:options table="t_remark_hdr"
						valuecolumn="remark_master_code"
						textcolumn="remark_master_code"
						where="<%=where%>"
						order="remark_master_code"
						selected="<%=selectRemarkTextForm.getSelectedRemarkMaster()%>" />
	</select>
	</td>
</tr>
<%
}
%>
<%
if (!hideRemarkDetail) {
%>
<tr valign="top">
	 <td class="col_label">
		Remark Detail Code:
	</td>
	 <td class="col_value">
		<%
			where = "company_code = '" + WebUtil.getAppropriateCompanyCode(session, ProjectConstants.SP_SHARE_REMARK) + "' and status = '"+ProjectConstants.GENERIC_ACTIVE+"'";

			where += " and remark_master_code = '" + selectRemarkTextForm.getSelectedRemarkMaster() + "'";
		%>
		<select name="selectedRemarkDtl" class="selectBox1" onchange="doSubmit('changeDtl');" <%=disabledHtml%> >
		<option value=""></option>
			<chtml:options table="t_remark_dtl"
						valuecolumn="remark_dtl_code"
						textcolumn="remark_dtl_code"
						where="<%=where%>"
						order="remark_dtl_code"
						selected="<%=selectRemarkTextForm.getSelectedRemarkDtl()%>" />
	</select>
	</td>
</tr>
<%
}
%>
<%
if (!hideRemarkAppend) {
%>
<tr valign="top">
    <td class="col_label">Append:
	</td>
    <td class="col_value">
        <input type="checkbox" property="appendTmp" value="<%=ProjectConstants.GENERIC_YES%>" <%= (selectRemarkTextForm.getAppend() != null && selectRemarkTextForm.getAppend().equals(ProjectConstants.GENERIC_YES))? "checked": "" %> onClick="javascript:doAppend();"/>
		<html:hidden property="append" value="<%= CommonUtil.nullToString(selectRemarkTextForm.getAppend(), \"0\")%>" />
    </td>
</tr>
<%
}
%>
<tr valign="top">
    <td class="col_label"></td>
    <td class="col_value">
        <input name="btn_ok" type="button" value="  OK  " onClick="javascript:doSubmit('ok');" class="button1" <%=readonly?"disabled":""%>>
	<input name="btn_cancel" type="button" value="Cancel" onClick="javascript:doSubmit('cancel');" class="button1" >
		<input name="btn_clear" type="button" value="Clear" onClick="javascript:doSubmit('erase');" class="button1" <%=readonly?"disabled":""%>>
    </td>
</tr>
<tr valign="top">
     <td class="col_label"><bean:write name="selectRemarkTextForm" property="remarkColumnName" filter="true"/>:</td>
     <td class="col_value"><html:textarea property="remarkText" rows="30" cols="80" styleClass="textarea1" readonly="<%=readonly%>" /></td>
</tr>
</table>

<%
if(useHtmlCode){
%>
<script language="javascript1.2">
var config = new Object();    // create new config object

//config.width = "98%";
config.height = "250px";
config.bodyStyle = 'background-color: white; font-family: "Arial"; font-size: 12pt;';
config.debug = 0;

// NOTE:  You can remove any of these blocks and use the default config!

config.toolbar = [
    ['fontname'],
    ['fontsize'],
    ['bold','italic','underline','strikethrough','separator'],
//    ['bold','italic','underline','separator'],
//  ['strikethrough','subscript','superscript','separator'],
    ['justifyleft','justifycenter','justifyright','separator'],
//    ['OrderedList','UnOrderedList','Outdent','Indent','separator'],
//    ['forecolor','backcolor','htmlmode','separator'],
    ['forecolor','backcolor']
//    ['HorizontalRule','Createlink','InsertImage','popupeditor','separator']
];

config.fontnames = {
    "Arial":           "arial, helvetica, sans-serif",
    "Courier New":     "courier new, courier, mono",
    "Georgia":         "Georgia, Times New Roman, Times, Serif",
    "Tahoma":          "Tahoma, Arial, Helvetica, sans-serif",
    "Times New Roman": "times new roman, times, serif",
    "Verdana":         "Verdana, Arial, Helvetica, sans-serif",
    "impact":          "impact",
    "WingDings":       "WingDings"
};
config.fontsizes = {
    "12 pt": "3",
    "14 pt": "4",
    "18 pt": "5"
  };

//config.stylesheet = "http://www.domain.com/sample.css";

config.fontstyles = [   // make sure classNames are defined in the page the content is being display as well in or they won't work!
  { name: "headline",     className: "headline",  classStyle: "font-family: arial black, arial; font-size: 28px; letter-spacing: -2px;" },
  { name: "arial red",    className: "headline2", classStyle: "font-family: arial black, arial; font-size: 12px; letter-spacing: -2px; color:red" },
  { name: "verdana blue", className: "headline4", classStyle: "font-family: verdana; font-size: 18px; letter-spacing: -2px; color:blue" }

// leave classStyle blank if it's defined in config.stylesheet (above), like this:
//  { name: "verdana blue", className: "headline4", classStyle: "" }
];

editor_generate('remarkText',config);
</script>
<%
}
%>



</html:form>
</body>